//
//  QuanziDetailViewController.m
//  YiqiMobile
//
//  Created by henry on 13-3-24.
//  Copyright (c) 2013年 henry. All rights reserved.
//

#define QUANZIBGTAG 801//圈子背景
#define QUANZILOGOTAG 802//圈子logo
#define QUANZISHENFENTAG 803//我的身份
#define QUANZITONGJITAG 804//圈子统计
#define QUANZISHENHETAG 805//圈子审核
#import "HomePageSecondViewController.h"
#import "Utility.h"
#import "Config.h"
#import "HomePageSecondViewCell.h"
#import "QuanziDetailViewController.h"
#import "AppDelegate.h"
#import "HomePageViewController.h"
#import "JSON.h"
#import "DefineAction.h"
#import "MBProgressHUD.h"
#import "BoweiListViewController.h"
#import "BowenPreviewViewController.h"
#import "QuanziTabBarController.h"
#import "GonggaoListViewController.h"


@implementation HomePageSecondViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad{
    [super viewDidLoad];
    [self tableviewHeader];
    //导航栏左边按钮
    self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc] initWithCustomView:[Utility customButton:self action:@selector(onClickNavAction:) normalImage:@"pushButton_normal.png" lightedImage:@"pushButton_hover.png" frame:CGRectMake(0, 0, 35, 35) title:nil tag:PUSHMENUBUTTONTAG]];
    //导航栏右边按钮
    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc] initWithCustomView:[Utility customButton:self action:@selector(onClickNavAction:) normalImage:@"moreButton_normal.png" lightedImage:@"moreButton_hover.png" frame:CGRectMake(0, 0, 35, 35) title:nil tag:PUSHMENUBUTTONTAG+1]];
    

    float tableHeight=UISCREEN_HEIGHT-22-49-44;
    self.mytableView=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, UISCREEN_WIDTH, tableHeight) style:UITableViewStylePlain];
     self.mytableView.separatorStyle=UITableViewCellEditingStyleNone;
    //self.mytableView.showsVerticalScrollIndicator=NO;
    self.mytableView.delegate=self;
    self.mytableView.dataSource=self;
    [self.view addSubview:self.mytableView];
    self.arrayList1=[NSMutableArray array];
    self.arrayList2=[NSMutableArray array];
    // Do any additional setup after loading the view from its nib.
    
      
}
-(void) viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    AppDelegate *app=(AppDelegate*)[[UIApplication sharedApplication] delegate];
    self.hidesBottomBarWhenPushed=NO;
    [app.tabBarController hideExistingTabBar];
    app.tabBarController.tabBarView.hidden=NO;
    HomePageViewController *homePageViewController=(HomePageViewController*)[[[self.tabBarController.viewControllers objectAtIndex:0] viewControllers] objectAtIndex:0];
    homePageViewController.isShowLevelPop=YES;
    UIView *rightPopView=[self.view  viewWithTag:HOMEPAGELPV];
    [rightPopView removeFromSuperview];
}

-(void) loadData:(NSDictionary*) param{
    self.quanziDict=param;
    self.navigationItem.titleView=[Utility getTitleView:[self.quanziDict objectForKey:@"str2"]];
    [self loadUserInfoFromServer];
}

-(void) loadUserInfoFromServer{
    AppDelegate *app=(AppDelegate*)[[UIApplication sharedApplication] delegate];
    if (app.status==NotReachable) {
        [Utility customAlertWithMsg:NETWORTERROE andTitle:ALRRTTITLE andDelagate:nil];
        return;
    }
    NSString *userId=[[NSUserDefaults standardUserDefaults] objectForKey:USERID];
    NSString *url=[NSString stringWithFormat:@"%@/%@?e.e0=%@&u.u0=%@",[Utility  getServerUrl],GETQUANZIINFOACTION,[self.quanziDict objectForKey:@"str1"],userId];
    self.request=[[URLRequest alloc] initWithPostURL:url andDelegate:self andPostData:nil andFile:nil];
      [[MBProgressHUD showHUDAddedTo:self.view animated:YES] setLabelText:LOADING_TITLE_DEFAULT];
    [self.request startLoadData];
}
//最新公告
-(void) getnewsGonggao{
    AppDelegate *app=(AppDelegate*)[[UIApplication sharedApplication] delegate];
    if (app.status==NotReachable) {
        [Utility customAlertWithMsg:NETWORTERROE andTitle:ALRRTTITLE andDelagate:nil];
        return;
    }
    NSString *userId=[[NSUserDefaults standardUserDefaults] objectForKey:USERID];
    NSString *url=[NSString stringWithFormat:@"%@/%@?e.e0=%@&u.u0=%@",[Utility  getServerUrl],QUANZI_NEWGG,[self.quanziDict objectForKey:@"str1"],userId];
    self.request=[[URLRequest alloc] initWithPostURL:url andDelegate:self andPostData:nil andFile:nil];
    [[MBProgressHUD showHUDAddedTo:self.view animated:YES] setLabelText:LOADING_TITLE_DEFAULT];
    [self.request startLoadData];
}
//最新博文
-(void) getnewsbw{
    AppDelegate *app=(AppDelegate*)[[UIApplication sharedApplication] delegate];
    if (app.status==NotReachable) {
        [Utility customAlertWithMsg:NETWORTERROE andTitle:ALRRTTITLE andDelagate:nil];
        return;
    }
    NSString *userId=[[NSUserDefaults standardUserDefaults] objectForKey:USERID];
    NSString *url=[NSString stringWithFormat:@"%@/%@?b.e0=%@&b.u0=%@",[Utility  getServerUrl],QUANZI_NEWB,[self.quanziDict objectForKey:@"str1"],userId];
    self.request=[[URLRequest alloc] initWithPostURL:url andDelegate:self andPostData:nil andFile:nil];
    [[MBProgressHUD showHUDAddedTo:self.view animated:YES] setLabelText:LOADING_TITLE_DEFAULT];
    [self.request startLoadData];
}

- (void)requestFinished:(id)context{
    [MBProgressHUD hideAllHUDsForView:self.view animated:NO];
    @try{
        NSDictionary *result=[context JSONValue];
        if (result!=nil&&[[result  objectForKey:@"code"] integerValue]==0) {
            if ([[result  objectForKey:@"method"] isEqualToString:GETQUANZIINFOACTION]) {
                self.quanziInfoDicy=[result objectForKey:@"data"];
                [self getnewsGonggao];
                [self.mytableView  reloadData];
            }else if ([[result  objectForKey:@"method"] isEqualToString:QUANZI_GUANZHUACTION]) {//关注
                [Utility customAlertWithMsg:@"您已成功关注圈子" andTitle:ALRRTTITLE andDelagate:nil];
                [self loadUserInfoFromServer];
            
            }else if ([[result  objectForKey:@"method"] isEqualToString:QUANZI_QUXIAOACTION]) {//取消关注
                [Utility customAlertWithMsg:@"你已经取消关注圈子" andTitle:ALRRTTITLE andDelagate:nil];
                 [self loadUserInfoFromServer];
                
            }else if ([[result  objectForKey:@"method"] isEqualToString:QUANZI_TUICHUACTION]) {//退出
                [Utility customAlertWithMsg:@"您已经推出圈子" andTitle:ALRRTTITLE andDelagate:nil];
                 [self loadUserInfoFromServer];
                
            }else if ([[result  objectForKey:@"method"] isEqualToString:QUANZI_JOINACTION]) {//加入
                [Utility customAlertWithMsg:@"您已成功加入此圈子" andTitle:ALRRTTITLE andDelagate:nil];
                 [self loadUserInfoFromServer];
            }else if ([[result  objectForKey:@"method"] isEqualToString:QUANZI_NEWGG]) {//最新公告
                [self.arrayList1 removeAllObjects];
                [self.arrayList1 addObjectsFromArray:[result objectForKey:@"list"]];
                 [self getnewsbw];
                
            }else if ([[result  objectForKey:@"method"] isEqualToString:QUANZI_NEWB]) {//最新博文
                [self.arrayList2 removeAllObjects];
                [self.arrayList2 addObjectsFromArray:[result objectForKey:@"list"]];
                 [self.mytableView  reloadData];
                
            }
            
        }else{
            [Utility customAlertWithMsg:PROCESSERROE andTitle:ALRRTTITLE andDelagate:nil];
        }
    }@catch (NSException *e) {
        [Utility customAlertWithMsg:NETWORTERROE andTitle:ALRRTTITLE andDelagate:nil];
    }
}

- (void)requestFailed:(id)context error:(NSString *)error{
    [MBProgressHUD hideAllHUDsForView:self.navigationController.view animated:NO];
    [Utility customAlertWithMsg:NETWORTERROE andTitle:ALRRTTITLE andDelagate:nil];
}

-(void) tableviewHeader{
    self.tableCell0View=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 330)];
    UIImageView *background=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 175)];
    background.tag=QUANZIBGTAG;
    background.userInteractionEnabled=YES;
    
    [self.tableCell0View addSubview:background];
    UIImageView *logo=[[UIImageView alloc] initWithFrame:CGRectMake(20, 125, 82, 82)];
    logo.tag=QUANZILOGOTAG;
    
    [self.tableCell0View addSubview:logo];
    UILabel *nickname=[Utility detailTextLabel:CGRectMake(105, 185, 100, 14)andFontSize:9.0f];
    nickname.font=[UIFont fontWithName:FONT_FAMILY size:9.0f];
    nickname.textColor=UIColorFromRGB(0x000000);
    nickname.tag=QUANZISHENFENTAG;
    
    [self.tableCell0View addSubview:nickname];
    self.tableCell0View.backgroundColor=[UIColor whiteColor];
    
    UIButton *customButton1 = [UIButton buttonWithType:UIButtonTypeCustom];
    customButton1.tag=HOMEPAGESECONTAG;
    customButton1.hidden=YES;
    [customButton1 addTarget:self action:@selector(onclickButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.tableCell0View addSubview:customButton1];
    
     UIButton *customButton2 = [UIButton buttonWithType:UIButtonTypeCustom];
     customButton2.tag=HOMEPAGESECONTAG+1;
     customButton2.hidden=YES;
     [customButton2 addTarget:self action:@selector(onclickButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.tableCell0View addSubview:customButton2];

     UILabel *label1=[Utility detailTextLabel:CGRectMake(16, 210, 200, 14) andFontSize:9.0];
     label1.tag=QUANZITONGJITAG;
     label1.textColor=UIColorFromRGB(0x000000);
     UILabel *label2=[Utility detailTextLabel:CGRectMake(16, 226, 200, 14) andFontSize:9.0];
     label2.tag=QUANZISHENHETAG;
     label2.textColor=UIColorFromRGB(0x000000);
    [self.tableCell0View addSubview:label1];
    [self.tableCell0View addSubview:label2];
    
    
    //滚动视图
    self.quanziMenu=[[QuanziMenu alloc] initWithFrame:CGRectMake(0, 240, self.view.frame.size.width, 90)];
    self.quanziMenu.delegate=self;
    [self.tableCell0View addSubview:self.quanziMenu];
}

-(void) showTabelCell0Data{
    if (!self.quanziInfoDicy) {
        return;
    }
    UIImageView *background=(UIImageView*)[self.tableCell0View viewWithTag:QUANZIBGTAG];
    UIImageView *logo=(UIImageView*)[self.tableCell0View viewWithTag:QUANZILOGOTAG];
     UILabel *nickname=(UILabel*)[self.tableCell0View viewWithTag:QUANZISHENFENTAG];
     UILabel *tongjiLabel=(UILabel*)[self.tableCell0View viewWithTag:QUANZITONGJITAG];
    UILabel *shenheLabel=(UILabel*)[self.tableCell0View viewWithTag:QUANZISHENHETAG];
    //背景
    NSString *backImageUrl=[self.quanziInfoDicy objectForKey:@"estr9"];
    UIImage *backImage=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:backImageUrl]]];
    if (!backImage) {
         background.image=[Utility imageNamed:@"quanzitopbg.png"];
    }
   //logo
    NSString *logoImageUrl=[self.quanziInfoDicy objectForKey:@"ustr4"];
    UIImage *logoImage=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:logoImageUrl]]];
    if (!logoImage) {
        logo.image=[Utility imageNamed:@"qz_logo.png"];
    }
    
    UIButton *button1=(UIButton*)[self.tableCell0View viewWithTag:HOMEPAGESECONTAG];
    UIButton *button2=(UIButton*)[self.tableCell0View viewWithTag:HOMEPAGESECONTAG+1];
    button1.hidden=YES;
    button2.hidden=YES;
    switch ([[self.quanziInfoDicy objectForKey:@"uint1"] integerValue]) {
        case 1:{//创建者－－管理设置
            nickname.text=[NSString stringWithFormat:@"%@",@"我是创建者"];
            button1.hidden=NO;
            button1.frame=CGRectMake(235, 175, 80, 33);
            [button1 setImage:[Utility imageNamed:@"qz_setting_normal.png"] forState:UIControlStateNormal];
            [button1 setImage:[Utility imageNamed:@"qz_setting_hover.png"] forState:UIControlStateSelected];
            
            break;
        }
        case 2:{//管理员－－管理设置
            button1.hidden=NO;
            nickname.text=[NSString stringWithFormat:@"%@",@"我是管理员"];
            button1.frame=CGRectMake(235, 175, 80, 33);
            [button1 setImage:[Utility imageNamed:@"qz_setting_normal.png"] forState:UIControlStateNormal];
            [button1 setImage:[Utility imageNamed:@"qz_setting_hover.png"] forState:UIControlStateSelected];
            break;
        }
        case 3:{//成员－－退出
            nickname.text=[NSString stringWithFormat:@"%@",@"我是圈子成员"];
            button2.hidden=NO;
            button2.frame=CGRectMake(235, 175, 80, 33);
            [button2 setImage:[Utility imageNamed:@"qz_logout_normal.png"] forState:UIControlStateNormal];
            [button2 setImage:[Utility imageNamed:@"qz_logout_hover.png"] forState:UIControlStateSelected];
            break;
        }
        case 4:{//关注者－－加入 取消关注
            nickname.text=[NSString stringWithFormat:@"%@",@"我是关注者"];
            button1.hidden=NO;
            button1.frame=CGRectMake(172, 175, 59, 31);
            [button1 setImage:[Utility imageNamed:@"quanzi_add_mormal.png"] forState:UIControlStateNormal];
            [button1 setImage:[Utility imageNamed:@"quanzi_add_mormal.png"] forState:UIControlStateSelected];
 
            button2.hidden=NO;
            button2.frame=CGRectMake(236, 175, 79, 30);
            [button2 setImage:[Utility imageNamed:@"qz_del_normal.png"] forState:UIControlStateNormal];
            [button2 setImage:[Utility imageNamed:@"qz_del_hover.png"] forState:UIControlStateSelected];
            break;
        }
        case 5:{//访客 －－加入、关注
            nickname.text=[NSString stringWithFormat:@"%@",@"我是访客"];
            button1.hidden=NO;
            button1.frame=CGRectMake(170.5, 175, 59, 31);
            [button1 setImage:[Utility imageNamed:@"quanzi_add_normal.png"] forState:UIControlStateNormal];
            [button1 setImage:[Utility imageNamed:@"quanzi_add_hover.png"] forState:UIControlStateSelected];
            
            button2.hidden=NO;
            button2.frame=CGRectMake(234.5, 175, 80.5, 31.5);
            [button2 setImage:[Utility imageNamed:@"quanzi_guanzhu_normal.png"] forState:UIControlStateNormal];
            [button2 setImage:[Utility imageNamed:@"quanzi_guanzhu_hover@.png"] forState:UIControlStateSelected];
            
            break;
        }
        default:{
            break;
        }
    }
    //统计
    tongjiLabel.text=[NSString stringWithFormat:@"成员:%@  关注:%@",[self.quanziInfoDicy objectForKey:@"ecount2"],[self.quanziInfoDicy objectForKey:@"ecount7"]];
    NSString *shenhe1=([[self.quanziInfoDicy objectForKey:@"eint2"] integerValue]==0)?@"":@"(不)";
     NSString *shenhe2=([[self.quanziInfoDicy objectForKey:@"eint3"] integerValue]==0)?@"":@"(不)";
    shenheLabel.text=[NSString stringWithFormat:@"加入%@需审核  博文%@需要审核",shenhe1,shenhe2];
    
    
    //NSDictionary *temp=self.quanziInfoDicy;
    NSArray *param=@[@{@"name":@"bw",@"count":[self.quanziInfoDicy objectForKey:@"ecount1"],@"flag":@"0"}
                     ,@{@"name":@"gg",@"count":[self.quanziInfoDicy objectForKey:@"ecount4"],@"flag":@"0"}
                     ,@{@"name":@"ly",@"count":[self.quanziInfoDicy objectForKey:@"ecount5"],@"flag":@"0"}
                     ,@{@"name":@"detail",@"count":@"0",@"flag":@"0"}
                     ];
    [self.quanziMenu showData:param];
}

-(void) onClickNavAction:(UIButton*) sender{
    UIViewController *homePageViewController=[self.navigationController.viewControllers objectAtIndex:0];
    [homePageViewController  performSelector:@selector(onClickAction:) withObject:sender];
}

//表视图委托
#pragma mark - Tableview datasource & delegates
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    switch (section) {
        case 0:{
            return nil;
            break;
        }
        case 1:{
            UIImageView *view=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 29)];
             view.image=[Utility imageNamed:@"qz_gg.png"];
            return view;
            break;
        }
        case 2:{
            UIImageView *view=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 29)];
             view.image=[Utility imageNamed:@"qz_bowen.png"];
            return view;
            break;
        }
        default:
            break;
    }
    return nil;
}

//指定有多少个分区(Section)，默认为1
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 3;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section==0) {
        return 1;
    }else if (section==1) {
            return [self.arrayList1 count];
    }else if (section==2) {
        return [self.arrayList2 count];
    }else{
        return 0;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section==0) {
        return 0.0;
    }
    return 29.0f;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==0) {
        return 330.0f;
    }
    return 61.5f;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellIdentity = @"quanziDetailViewCell";
    static NSString *cellIdentity0 = @"quanziDetailViewCell0";
    HomePageSecondViewCell *cell = nil;
    if (indexPath.section==0) {
            cell = (HomePageSecondViewCell*)[tableView dequeueReusableCellWithIdentifier:cellIdentity0];
            if (cell ==  nil) {
                cell = (HomePageSecondViewCell*)[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentity0];
            }
             cell.selectionStyle=UITableViewCellSelectionStyleNone;
            [cell addSubview:self.tableCell0View];
        [self showTabelCell0Data];
    }else {
            cell = (HomePageSecondViewCell*)[tableView dequeueReusableCellWithIdentifier:cellIdentity];
            if (cell ==  nil) {
                cell = [[HomePageSecondViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentity];
            }
               
            if (indexPath.section==1) {
                 NSDictionary *dict = [self.arrayList1  objectAtIndex:indexPath.row];
                cell.label1.text=[dict objectForKey:@"gg1"];
                cell.label1.font=[UIFont fontWithName:FONT_FAMILY size:15.0f];
                cell.label2.text=[dict objectForKey:@"gg4"];
            }else if(indexPath.section==2){
                 NSDictionary *dict = [self.arrayList2  objectAtIndex:indexPath.row];
                NSString *date=[Utility strFromSecond:[dict objectForKey:@"dat4"] andFormat:@"yyyy-MM-dd HH:mm"];
                cell.label1.text=[dict objectForKey:@"str2"];
                cell.label1.font=[UIFont fontWithName:FONT_FAMILY size:12.0f];
                cell.label2.text=[NSString stringWithFormat:@"%@  阅读:%@ 收藏:%@ 评论:%@ 分享:%@",date,[dict objectForKey:@"count3"],[dict objectForKey:@"count6"],[dict objectForKey:@"count5"],[dict objectForKey:@"count4"]];
                if ([[dict objectForKey:@"count8"] integerValue]==0) {
                    cell.rightView.hidden=NO;
                }
            }
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==1) {//公告
        
    }else if (indexPath.section==2) {//博文
        BowenPreviewViewController *bowen=[[BowenPreviewViewController alloc] initWithNibName:nil bundle:nil];
        NSDictionary *dcit=[self.arrayList2 objectAtIndex:indexPath.row];
        [bowen loadDataFromServer:[dcit objectForKey:@"str1"]];
        [self.navigationController pushViewController:bowen animated:YES];

    }
}



-(IBAction)onclickButtonAction:(id)sender{
    UIButton *button=(UIButton*)sender;
    if (button.tag==HOMEPAGESECONTAG) {
        switch ([[self.quanziInfoDicy objectForKey:@"uint1"] integerValue]) {
            case 1:{//创建者－－管理设置
                
                [self openQuanmanageAction:nil];
                break;
            }
            case 2:{//管理员－－管理设置
                 [self openQuanmanageAction:nil];
                break;
            }

            case 4:{//关注者－－加入
                [self joinQuanzi];
                break;
            }
            case 5:{//访客 －－加入
                [self joinQuanzi];
                break;
            }
            default:{
                break;
            }
        }
        
    }else if(button.tag==HOMEPAGESECONTAG+1){
            switch ([[self.quanziInfoDicy objectForKey:@"uint1"] integerValue]) {
            case 3:{//成员－－退出
                [self tuichuQuanzi];
                break;
            }
            case 4:{//关注者－－取消关注
                [self quanziGuanzhu:QUANZI_QUXIAOACTION];
                break;
            }
            case 5:{//访客 －－关注
                [self quanziGuanzhu:QUANZI_GUANZHUACTION];
                break;
            }
            default:{
                break;
            }
        }

    
    }


}

/*u.u0	N	关注者（也就是当前登录者）
id	N	被关注的对象ID
type	N	被关注的对象类型(暂时只关注圈子其余预留) 1 圈子 2 专题 3 博文 4 供稿 5 用户
 */
-(void) quanziGuanzhu:(NSString*)actionName{
    AppDelegate *app=(AppDelegate*)[[UIApplication sharedApplication] delegate];
    if (app.status==NotReachable) {
        [Utility customAlertWithMsg:NETWORTERROE andTitle:ALRRTTITLE andDelagate:nil];
        return;
    }
    NSString *userId=[[NSUserDefaults standardUserDefaults] objectForKey:USERID];
    NSString *url=[NSString stringWithFormat:@"%@/%@?u.u0=%@&id=%@&type=%@",[Utility  getServerUrl],actionName,userId,[self.quanziDict objectForKey:@"str1"],@"1"];
    self.request=[[URLRequest alloc] initWithPostURL:url andDelegate:self andPostData:nil andFile:nil];
    [[MBProgressHUD showHUDAddedTo:self.view animated:YES] setLabelText:LOADING_TITLE_DEFAULT];
    [self.request startLoadData];
}

/*
 e.e0	N	需要加入的圈子ID
 u.u0	N	需要加入的用户ID
 str1	Y	接受到的邀请码  没有就传 “”
 str2	Y	需要审核的话 申请的理由  没有就传 “”
 */
-(void) joinQuanzi{
    AppDelegate *app=(AppDelegate*)[[UIApplication sharedApplication] delegate];
    if (app.status==NotReachable) {
        [Utility customAlertWithMsg:NETWORTERROE andTitle:ALRRTTITLE andDelagate:nil];
        return;
    }
    NSString *userId=[[NSUserDefaults standardUserDefaults] objectForKey:USERID];
    NSString *url=[NSString stringWithFormat:@"%@/%@?u.u0=%@&e.e0=%@&str1=%@&str2=%@",[Utility  getServerUrl],QUANZI_JOINACTION,userId,[self.quanziDict objectForKey:@"str1"],@"",@""];
    self.request=[[URLRequest alloc] initWithPostURL:url andDelegate:self andPostData:nil andFile:nil];
    [[MBProgressHUD showHUDAddedTo:self.view animated:YES] setLabelText:LOADING_TITLE_DEFAULT];
    [self.request startLoadData];
}

-(void) tuichuQuanzi{
    AppDelegate *app=(AppDelegate*)[[UIApplication sharedApplication] delegate];
    if (app.status==NotReachable) {
        [Utility customAlertWithMsg:NETWORTERROE andTitle:ALRRTTITLE andDelagate:nil];
        return;
    }
    NSString *userId=[[NSUserDefaults standardUserDefaults] objectForKey:USERID];
    NSString *url=[NSString stringWithFormat:@"%@/%@?u.u0=%@&id=%@",[Utility  getServerUrl],QUANZI_TUICHUACTION,userId,[self.quanziDict objectForKey:@"str1"]];
    self.request=[[URLRequest alloc] initWithPostURL:url andDelegate:self andPostData:nil andFile:nil];
    [[MBProgressHUD showHUDAddedTo:self.view animated:YES] setLabelText:LOADING_TITLE_DEFAULT];
    [self.request startLoadData];
}



-(void) onclickScrollButton:(NSUInteger)category{
    switch (category) {
        case 0:{
            BoweiListViewController *boweiListViewController=[[BoweiListViewController alloc] initWithNibName:nil bundle:nil];
            AppDelegate *app=(AppDelegate*)[[UIApplication sharedApplication] delegate];
            boweiListViewController.hidesBottomBarWhenPushed=YES;
            [app.tabBarController hideExistingTabBar];
            app.tabBarController.tabBarView.hidden=YES;
            [boweiListViewController  loadDataFromServer:[self.quanziDict objectForKey:@"str1"] andPage:1];
            [self.navigationController pushViewController:boweiListViewController animated:YES];
            break;
        }
        case 1:{
            GonggaoListViewController *gonggaoListViewController=[[GonggaoListViewController alloc] initWithNibName:nil bundle:nil];
            AppDelegate *app=(AppDelegate*)[[UIApplication sharedApplication] delegate];
            gonggaoListViewController.hidesBottomBarWhenPushed=YES;
            [app.tabBarController hideExistingTabBar];
            app.tabBarController.tabBarView.hidden=YES;
            [gonggaoListViewController loadDataFromServer:[self.quanziDict objectForKey:@"str1"] andPage:1];
            [self.navigationController pushViewController:gonggaoListViewController animated:YES];
            break;
        }
        case 2:{
            [Utility customAlertWithMsg:@"请添加数据,暂未开发" andTitle:@"提示" andDelagate:self];
            NSLog(@"%d",category);
            break;
        }
        case 3:{
            QuanziDetailViewController *quanzi=[[QuanziDetailViewController alloc] initWithNibName:nil bundle:nil];
            AppDelegate *app=(AppDelegate*)[[UIApplication sharedApplication] delegate];
            quanzi.hidesBottomBarWhenPushed=YES;
            [app.tabBarController hideExistingTabBar];
            app.tabBarController.tabBarView.hidden=YES;
            [self.navigationController pushViewController:quanzi animated:YES];
            break;
        }
        default:
            break;
    }

}
-(IBAction)openQuanmanageAction:(id)sender{
    AppDelegate *app=(AppDelegate*)[[UIApplication sharedApplication] delegate];
    app.quanziId=[self.quanziDict objectForKey:@"str1"];
    QuanziTabBarController *quanziTabBarController=[[QuanziTabBarController alloc] initWithNibName:nil bundle:nil];
    [self  presentViewController:quanziTabBarController animated:YES completion:nil];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
